package c2.group.business.tb;

import cate.common.table.d.GDThrone;
import cate.game.pvp.throne.data.TBGroupData;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

@NoteClass("王座争霸-等级组模块")
public abstract class TBGroupModule<T extends TBGroupData> extends TBSubModule {

	@NoteField("等级组数据")
	protected Map<Integer, T> groupMap = new HashMap<>();

	@Override
	public void initDependent() throws Exception {
		super.initDependent();
		for (Integer levelGroup : GDThrone.LevelGroup.ALL) {
			if (!groupMap.containsKey(levelGroup)) {
				T data = buildData();
				data.levelGroup = levelGroup;
				data.init();
				groupMap.put(levelGroup, data);
			}
		}
	}

	protected abstract T buildData();

	public T getGroup(int group){
		return groupMap.get(group);
	}

	public void forGroups(Consumer<T> consumer) {
		groupMap.values().forEach(consumer);
	}
}
